
package provide pdtk_text 0.1

############ pdtk_text_new -- create a new text object #2###########
proc pdtk_text_new {mycanvas tags x y text font_size color} {
    $mycanvas create text $x $y -tags $tags -text $text -fill $color \
        -anchor nw -font [get_font_for_size $font_size]
    set mytag [lindex $tags 0]
    $mycanvas bind $mytag <Home> "$mycanvas icursor $mytag 0"
    $mycanvas bind $mytag <End>  "$mycanvas icursor $mytag end"
    # select all
    $mycanvas bind $mytag <Triple-ButtonRelease-1>  \
        "$mycanvas select from $mytag 0; $mycanvas select to $mytag end;"
    if {$::windowingsystem eq "aqua"} { # emacs bindings for Mac OS X
        $mycanvas bind $mytag <Control-a> "$mycanvas icursor $mytag 0"
        $mycanvas bind $mytag <Control-e> "$mycanvas icursor $mytag end"
    }
}

################ pdtk_text_set -- change the text ##################
proc pdtk_text_set {mycanvas tag text} {
    $mycanvas itemconfig $tag -text $text
}

############# pdtk_pastetext - paste into text #####################
proc pdtk_pastetext {args} {
    catch {set pdtk_pastebuffer [clipboard get]}
    for {set i 0} {$i < [string length $pdtk_pastebuffer]} {incr i 1} {
        set cha [string index $pdtk_pastebuffer $i]
        scan $cha %c keynum
        pdsend "pd key 1 $keynum 0"
    }
}
